package MapDemo.TreeMapdemo.demo1;

public class Student implements Comparable<Student>{
    private String name;
    private int age;
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public Student() {
    }
    

    /**
     * @return String return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return int return the age
     */
    public int getAge() {
        return age;
    }

    /**
     * @param age the age to set
     */
    public void setAge(int age) {
        this.age = age;
    }
    @Override
    public int compareTo(Student o) {
        int i = this.getAge() - o.getAge();
        // 如果年龄相同则比较姓名
        i = i == 0 ? this.getName().compareTo(o.getName()) : i;
        return i;

    }
    public void show(){
        System.out.println(this.getName() + "年龄为：" + this.getAge());
    }

}
